<?php 
if(isset($_GET['action']))
	$action=$_GET['action'];
else
	$action='select';



$data=array(
	'name'=>'',
	'email'=>'',
	'phone'=>'',
	'address'=>'',
	'city'=>'Santiago',
	'postalcode'=>'15000',
	'gender'=>'',
	'description'=>'',
	'provinces_id'=>'1',
	'likes'=>array(),
	'languages'=>array()
);


switch($action)
{
	case 'update':
		if($_POST)
		{
			$user=new Acl_Users_Users($database);
			$user->updateUser($_POST,$_FILES);
			header('Location: ?controller=users');
			break;
		}			
		else 
		{
			$user=new Acl_Users_Users($database);
			$data=$user->getUser($_GET['id']);
		}
				
	case 'insert':	
		if($_POST)
		{
			$user=new Acl_Users_Users($database);
			$id=$user->insertUser($_POST,$_FILES);
			header('Location: ?controller=users');
		}			
		else 
			include ($_SERVER['DOCUMENT_ROOT']."/../application/views/scripts/users/insert.php");
	break;
	case 'delete':
		if($_POST)
		{
			if(isset($_POST['delete']))
			{
				$user=new Acl_Users_Users($database);
				$user->deleteUser($_POST);
			}
			header('Location: ?controller=users&action=select');
		}			
		else
		{
			$user=new Acl_Users_Users($database);
			$data=$user->getUser($_GET['id']);
			include ($_SERVER['DOCUMENT_ROOT']."/../application/views/scripts/users/delete.php");
		}
			
	break;
	case 'viewUser':
		include_once ($_SERVER['DOCUMENT_ROOT'].'/../application/views/scripts/users/viewUser.php');		 
	break;
	case 'select':
	default:
		$user=new Acl_Users_Users($database);
		$arrayUsers=$user->getUsers();		
		include_once ($_SERVER['DOCUMENT_ROOT'].'/../application/views/scripts/users/select.php');
		
	break;
}

